package com.tsing.wms.controller;

import com.tsing.wms.service.IStockService;
import com.tsing.wms.util.ResultUtil;
import com.tsing.wms.valid.AddGroup;
import com.tsing.wms.valid.UpdateGroup;
import com.tsing.wms.vo.PageResultVO;
import com.tsing.wms.vo.ResultData;
import com.tsing.wms.vo.req.IdReqVO;
import com.tsing.wms.vo.req.StockReqVO;
import com.tsing.wms.vo.req.SupplierPageReqVO;
import com.tsing.wms.vo.resp.StockRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author TheTsing
 * @create 2022-04-17 15:32
 */
@Api(tags = "库存管理")
@RestController
@RequestMapping("/stock")
public class StockController {

    @Autowired
    private IStockService stockService;

    @PostMapping("/addStock")
    @ApiOperation(value = "新增库存")
    public ResultData addStock(@Validated({AddGroup.class}) @RequestBody StockReqVO reqVO, HttpServletRequest request) {
        stockService.addStock(reqVO, request);
        return ResultUtil.success();
    }

    @GetMapping("/getStock")
    @ApiOperation(value = "查询库存详情")
    public ResultData<StockRespVO> getStock(@Validated IdReqVO reqVO) {
        return ResultUtil.success(stockService.getStock(reqVO));
    }

    @PutMapping("/updateStock")
    @ApiOperation(value = "修改库存")
    public ResultData updateStock(@Validated({UpdateGroup.class}) @RequestBody StockReqVO reqVO, HttpServletRequest request) {
        stockService.updateStock(reqVO, request);
        return ResultUtil.success();
    }

    @GetMapping("/stockPage")
    @ApiOperation(value = "库存分页")
    public ResultData<PageResultVO<StockRespVO>> stockPage(@Validated SupplierPageReqVO reqVO) {
        return ResultUtil.success(stockService.stockPage(reqVO));
    }


}
